<div class="sm-pop">
    <form id="list_form_tag" class="layui-form">
    	<div class="layui-form-item " >
    		<div class="layui-inline right">
                <button class="layui-btn btn-danger" id="tagstouser_sync" type="button">同步标签下粉丝</button>
                <button class="layui-btn btn-danger" id="removetagforuser" type="button">移出标签</button>
            </div>
         </div>
        <table id="fans" class="layui-hide" lay-filter="fans"></table>
        <input type="hidden" name="fans">
        <input type="hidden" name="id" id="tagId" value="<%=id%>">
    </form>
</div>
<script>

    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;

        var fansArr=[];
        var tableObjf = table.render({
            id: 'fans',
            elem: '#fans',
            url: '/userTag/getUserListByTag',
            where:{id: $("#tagId").val() },
            align: "center",
            cols: [[ //表头
                {type: 'checkbox'},
                {type: 'numbers', title: '序号',width:50},
                {field: 'nicknameStr', title: '昵称', width: 150, align: 'center'},
                {field: 'headimgurl', title: '头像', width: 80, align: 'center',templet:function (d) {
                    return "<img class='fans-portrait' style='width:50px;height:50px;' src=" + d.headimgurl + " />"
                }},
                {field: 'gender', title: '性别', align: 'center',templet:function (d) {
                    return d.gender == 1 ? '男' : '女';
                }},
                {field: 'city', title: '省/市', width: 150,align: 'center',templet:function (d) {
                    return (d.province + '-' + d.city);
            }}
            ]],
        });
        // 用户批量移出标签
        $("#removetagforuser").click(function () {
        	var data = table.checkStatus('fans').data;//已选中数据
            if (data.length == 0) {
                layer.msg("至少选择一条");
                return;
            }
            var arr = [];     //选中数组
            for (var i = 0; i < data.length; i++) {
                arr.push(data[i].openId)
            }
            layer.confirm('确认要移出粉丝？', {
                icon: 7,
                title: "提示",
                btn: ['确认', '取消'] //按钮
            }, function () {
                smartAui.ajax({
                    loading:true,
                    url: '/userTag/removeUserForTag',
                    data: {
                    	id: $("#tagId").val(),
                    	"openIds": arr
                    	},
                    success: function (result) {
                    	layer.closeAll('loading');
                        if (result.success) {
                            layer.msg("移出成功");
                            smartAui.reloadTable(tableObjf,"list_form_tag");
                        }
                    },
                    error: function () {
                    	layer.closeAll('loading');
                        layer.msg("移出异常");
                    }
                })
            }, function () {
                layer.closeAll();
            });
        });
        // 批量同步用户标签
        $("#tagstouser_sync").click(function () {
            layer.confirm('确认要同步粉丝？', {
                icon: 7,
                title: "提示",
                btn: ['确认', '取消'] //按钮
            }, function () {
                smartAui.ajax({
                    loading:true,
                    url: '/userTag/syncUsersByTag',
                    data: {id: $("#tagId").val()},
                    success: function (result) {
                        if (result.success) {
                            layer.msg("同步成功");
                            smartAui.reloadTable(tableObjf,"list_form_tag");
                        }
                    },
                    error: function () {
                    	layer.closeAll('loading');
                        layer.msg("同步异常");
                    }
                })
            }, function () {
                layer.closeAll();
            });
        });
    });
</script>